package com.kunteng.exchangeboard.cotroller;

import com.kunteng.exchangeboard.mqtt.api.MQTTClient;
import com.kunteng.exchangeboard.mqtt.api.MQTTSenderHandler;
import com.kunteng.exchangeboard.mqtt.basic.CMD;
import com.kunteng.exchangeboard.mqtt.basic.ICMDCallback;
import com.kunteng.exchangeboard.mqtt.get.CMD_METHOD_Down_GetPoePortStatus;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.eclipse.paho.client.mqttv3.MqttException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ShiYun on 2016/9/22 0022.
 */
public class PortInfo extends HttpServlet {

    MQTTSenderHandler mqttSenderHandler = new MQTTSenderHandler();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String port = req.getParameter("port");
        JSONObject jsonObject = new JSONObject();
        int p=Integer.parseInt(port);
        String status = mqttSenderHandler.getStatusByPort(p);
        jsonObject.put("status", status);
        JSONArray apmacs = mqttSenderHandler.getMACByPort(p);
        jsonObject.put("ap", apmacs);
        PrintWriter printWriter = resp.getWriter();
        printWriter.println(jsonObject);
        printWriter.close();
    }
}
